#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2022/4/10 11:06 上午
# @Author : wang
# @Email : 136697880@qq.com
# @File : account.py
# @Project : bugmgr
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from .. import forms


def register(request):
    if request.method == 'GET':
        form = forms.UserInfoForm()
        return render(request, 'account/register.html', locals())
    if request.method == 'POST':
        print("request.POST:", request.POST)
        form = forms.UserInfoForm(data=request.POST)
        if form.is_valid():
            form.save()
            return JsonResponse({'status': True, 'data': 'register'})
        return JsonResponse({"status": False, "error": form.errors})


def login_sms(request):
    """短信登录"""
    form = forms.LoginForm()
    return render(request, 'account/login_sms.html', locals())


def send_sms(request):
    form = forms.SendsmsForm(request, data=request.POST)
    if form.is_valid():
        return JsonResponse({"status": "success"})
    return JsonResponse({"status": "fail", "error": form.errors})
